import base64
from typing import List

import shortuuid
from peewee import JOIN

from afast_core.core_libs.captcha.cilent import generate_captcha
from afast_core.core_tools.jwt_helper import SimpleAuth
from infirmary_admin_src.infirmary_common.infirmary_controller import IAsyncSessionBaseController, IBaseController
from infirmary_admin_src.infirmary_common.infirmary_controller.rest_controller_with_depends import \
    RestControllerWithDepends
from fastapi import Request, Depends, Path

from infirmary_admin_src.infirmary_smart_admin.infirmary_biz.infirmary.businesses.schemas import SchemaBase
from infirmary_admin_src.infirmary_smart_admin.infirmary_biz.support.services import SupportBusinesses
from infirmary_admin_src.infirmary_smart_admin.infirmary_utils.convert2_help import convert_dict_to_camel_case


class XParam(SchemaBase):
    '''
    账号密码登录参数
    '''
    searchWord: str = ''
    pageNum: int = 1
    pageSize: int = 10


class IController(IBaseController):
    '''
    定制相关约束检测函数逻辑步序
    '''

    def __init__(self, *, request: Request,
                 schema_param: XParam,
                 ):
        super().__init__(request=request)
        # 入参参数
        # 入参参数
        self.schema_param = schema_param


@RestControllerWithDepends()
class SupportDictKeyQueryController(IController):

    def business_login(self):
        pass
        _result_nums_total, lists = SupportBusinesses.get_dict_key_list(
            searchWord=self.schema_param.searchWord,
            pageNum=self.schema_param.pageNum,
            pageSize=self.schema_param.pageSize,
        )
        listdata = [convert_dict_to_camel_case(v,keepkey='dictKeyId') for v in lists]
        return {
            'emptyFlag': False if _result_nums_total > 0 else True,
            'list':listdata,
            'pageNum':self.schema_param.pageNum,
            'pageSize': self.schema_param.pageSize,
            'pages':_result_nums_total/len(listdata) if _result_nums_total > 0 else 0,
            'total':_result_nums_total
        }
